package main;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;

public class Manager {
	ArrayList<double[]> points;
	public Car car;
	public boolean[] keys = new boolean[255];
	public int WIDTH, HEIGHT;
	public double CHANGE = .02;
	private static double eraseTrue = 0;

	public Manager(int w, int h) {
		points = new ArrayList<double[]>();
		WIDTH = w;
		HEIGHT = h;
		car = new Car(100, 100);
		for (boolean i : keys) {
			i = false;
		}
	}

	public void draw(Graphics g) {
		if (keys[49]) {
			CHANGE = .04;
		} else if (keys[50]) {
			CHANGE = 1;
		} else {
			CHANGE = .02;
		}
		if (keys[37]) {
			car.angleChange += CHANGE / 1;
		}
		if (keys[38]) {
			car.velocity += CHANGE;
		}
		if (keys[39]) {
			car.angleChange -= CHANGE / 1;
		}
		if (keys[40]) {
			car.velocity -= CHANGE;
		}

		if ((Math.abs(car.xSpeed) > .1 || Math.abs(car.ySpeed) > .1)) {
			points.add(new double[] { car.x + 1, car.y });
			points.add(new double[] { car.x - 1, car.y });

		}

		if (eraseTrue > 0) {
			eraseTrue -= .5 + points.size() / 1000;
		}
		if (eraseTrue <= 0) {
			try {
				points.remove(0);
				points.remove(0);
			} catch (Exception e) {
			}
			eraseTrue += 2;
		}
		for (double[] i : points) {
			g.setColor(Color.blue);
			g.drawLine((int) i[0], (int) i[1], (int) i[0], (int) i[1]);
		}
		car.draw(g, this);
	}
}
